﻿using System.Windows;
using System.Windows.Controls;
using ImageAppViewModels;
using WpfImageDuplicates;

namespace Stats.Plugin
{
    /// <summary>
    /// Interaction logic for FileCollectionStatsView.xaml
    /// </summary>
    public partial class FileCollectionStatsView : UserControl
    {
        public static readonly DependencyProperty FileImageCollectionStatsViewModelProperty =
            DependencyProperty.Register("FileImageCollectionStatsViewModel", typeof(FileImageCollectionStatsViewModel), typeof(FileCollectionStatsView), new PropertyMetadata(null, OnFileImageCollectionStatsViewModelPropertyChanged));

        public FileImageCollectionStatsViewModel FileImageCollectionStatsViewModel
        {
            get { return (FileImageCollectionStatsViewModel)GetValue(FileImageCollectionStatsViewModelProperty); }
            set { SetValue(FileImageCollectionStatsViewModelProperty, value); }
        }

        private static void OnFileImageCollectionStatsViewModelPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            FileCollectionStatsView source = d as FileCollectionStatsView;
            source.UpdateFileImageCollectionStatsViewModel(e.NewValue as FileImageCollectionStatsViewModel);
        }

        private void UpdateFileImageCollectionStatsViewModel(FileImageCollectionStatsViewModel ViewStats)
        {
            FileImageCollectionStatsViewModel = ViewStats;

            // Let the UI bind to the view-model.
            this.DataContext = FileImageCollectionStatsViewModel;
            grid.DataContext = FileImageCollectionStatsViewModel;            
        }
        
        public FileCollectionStatsView()
        {
            InitializeComponent();
        }

        private void ClearStats(object sender, System.Windows.Input.ExecutedRoutedEventArgs e)
        {
            GeneralCommands.ClearStatsCommand.Execute();
        }

    }
}
